package io.xccit.race.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.xccit.common.annotation.Log;
import io.xccit.common.core.controller.BaseController;
import io.xccit.common.core.domain.AjaxResult;
import io.xccit.common.enums.BusinessType;
import io.xccit.race.domain.RaceCompetitionRules;
import io.xccit.race.service.IRaceCompetitionRulesService;
import io.xccit.common.utils.poi.ExcelUtil;
import io.xccit.common.core.page.TableDataInfo;

/**
 * 赛制管理Controller
 * 
 * @author ywx
 * @date 2025-10-10
 */
@RestController
@RequestMapping("/race/competitionRules")
public class RaceCompetitionRulesController extends BaseController
{
    @Autowired
    private IRaceCompetitionRulesService raceCompetitionRulesService;

    /**
     * 查询赛制管理列表
     */
    @PreAuthorize("@ss.hasPermi('race:competitionRules:list')")
    @GetMapping("/list")
    public TableDataInfo list(RaceCompetitionRules raceCompetitionRules)
    {
        startPage();
        List<RaceCompetitionRules> list = raceCompetitionRulesService.selectRaceCompetitionRulesList(raceCompetitionRules);
        return getDataTable(list);
    }

    /**
     * 导出赛制管理列表
     */
    @PreAuthorize("@ss.hasPermi('race:competitionRules:export')")
    @Log(title = "赛制管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RaceCompetitionRules raceCompetitionRules)
    {
        List<RaceCompetitionRules> list = raceCompetitionRulesService.selectRaceCompetitionRulesList(raceCompetitionRules);
        ExcelUtil<RaceCompetitionRules> util = new ExcelUtil<RaceCompetitionRules>(RaceCompetitionRules.class);
        util.exportExcel(response, list, "赛制管理数据");
    }

    /**
     * 获取所有赛制列表（用于下拉选择）
     */
    @GetMapping("/all")
    public AjaxResult getAllRules()
    {
        RaceCompetitionRules raceCompetitionRules = new RaceCompetitionRules();
        List<RaceCompetitionRules> list = raceCompetitionRulesService.selectRaceCompetitionRulesList(raceCompetitionRules);
        return success(list);
    }

    /**
     * 获取赛制管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('race:competitionRules:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(raceCompetitionRulesService.selectRaceCompetitionRulesById(id));
    }

    /**
     * 新增赛制管理
     */
    @PreAuthorize("@ss.hasPermi('race:competitionRules:add')")
    @Log(title = "赛制管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RaceCompetitionRules raceCompetitionRules)
    {
        return toAjax(raceCompetitionRulesService.insertRaceCompetitionRules(raceCompetitionRules));
    }

    /**
     * 修改赛制管理
     */
    @PreAuthorize("@ss.hasPermi('race:competitionRules:edit')")
    @Log(title = "赛制管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RaceCompetitionRules raceCompetitionRules)
    {
        return toAjax(raceCompetitionRulesService.updateRaceCompetitionRules(raceCompetitionRules));
    }

    /**
     * 删除赛制管理
     */
    @PreAuthorize("@ss.hasPermi('race:competitionRules:remove')")
    @Log(title = "赛制管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(raceCompetitionRulesService.deleteRaceCompetitionRulesByIds(ids));
    }
}
